package com.itheima.d3_udp2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * 目标：完成UDP通信快速入门-服务端反复的收
 */
public class Server {
    public static void main(String[] args) throws Exception{
        //创建服务端对象
        DatagramSocket datagramSocket = new DatagramSocket(6666);

        //接收数据
        while (true) {
            byte[] data = new byte[1024];
            DatagramPacket packet = new DatagramPacket(data, data.length);
            datagramSocket.receive(packet);
            //打印接受的数据
            int len = packet.getLength();
            System.out.println(new String(data,0,len));
        }
        //资源释放
//        datagramSocket.close(); //Unreachable statement


    }
}
